package com.youdoneed.community.accounts.service;

import com.github.pagehelper.PageHelper;
import com.youdoneed.community.accounts.dao.AccounttypeMapper;
import com.youdoneed.community.accounts.entity.Accounttype;
import com.youdoneed.community.common.utils.StringUUIdUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class AccountTypeService {

    private final Logger logger = LoggerFactory.getLogger(AccountTypeService.class);
    @Autowired
    AccounttypeMapper accounttypeMapper;

    @Transactional
    public boolean save(Accounttype type) {
        try {
            type.setAccountType(StringUUIdUtil.getUUID());
            accounttypeMapper.insert(type);
            return true;
        } catch (Exception e) {
            logger.error("差旅费用类型保存错误:" + e);
            return false;
        }
    }

    @Transactional
    public boolean update(Accounttype type) {
        try {
            accounttypeMapper.updateByPrimaryKey(type);
            return true;
        } catch (Exception e) {
            logger.error("差旅费用类型更新错误:" + e);
            return false;
        }
    }

    @Transactional
    public boolean delete(String accountType) {
        try {
            accounttypeMapper.deleteByPrimaryKey(accountType);
            return true;
        } catch (Exception e) {
            logger.error("差旅费用类型删除错误:" + e);
            return false;
        }
    }

    @Transactional
    public Accounttype selectById(String id) {
        try {
            return accounttypeMapper.selectByPrimaryKey(id);
        } catch (Exception e) {
            logger.error("差旅费用类型按ID查询错误:" + e);
            return null;
        }
    }

    /*@Transactional
    public List<Accounttype> selectParam(Map param){
        try {
            return accounttypeMapper.selectParam(param);
        } catch (Exception e) {
            logger.error("差旅费用类型查询错误:"+e);
            return null;
        }
    }

    @Transactional
    public List<Accounttype> selectParam_page(Map param){
        try {
            return accounttypeMapper.selectParam_page(param);
        } catch (Exception e) {
            logger.error("差旅费用类型分页查询错误:"+e);
            return null;
        }
    }*/
    @Transactional
    public List<Accounttype> selectParam(Map param) {
        try {
            return accounttypeMapper.selectParam(param);
        } catch (Exception e) {
            logger.error("差旅费用类型分页查询错误:" + e);
            return null;
        }
    }

    //	@Transactional
//    public List<Accounttype> selectParam_page(Map param){
//    	try {
//    		return accounttypeMapper.selectParam_page(param);
//		} catch (Exception e) {
//			logger.error("差旅费用类型分页查询错误:"+e);
//			return null;
//		}
//    }
    @Transactional
    public List<Accounttype> selectParamPage(Accounttype accounttype, int limit, int offset) {
        try {
            PageHelper.startPage(offset, limit);
            List<Accounttype> list = accounttypeMapper.selectParamPage(accounttype);
            return list;
        } catch (Exception e) {
            logger.error("差旅费用类型分页查询错误:" + e);
            return null;
        }
    }
}
